package com.ggb.reactive.repository

import com.ggb.reactive.domain.entity.AddressBook
import org.springframework.data.r2dbc.repository.Modifying
import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Repository
interface AddressBookRepository : ReactiveCrudRepository<AddressBook, Long> {
    fun findAllByUserId(userId: Long): Flux<AddressBook>
    @Modifying
    @Query("update address_book set is_default = :default where id = :id")
    fun updateIsDefaultById(default: Int?, id: Long): Mono<Int>
    @Modifying
    @Query("update address_book set is_default = 0 where user_id = :userId")
    fun setNotDefaultByUserId(userId: Long): Mono<Int>
    fun findByUserIdAndIsDefault(userId: Long, i: Int): Mono<AddressBook?>
}